package com.humh.library.model;


import java.time.LocalDate;

// 借书记录类

public class LoanRecord {
  private Reader reader;
  private Book book;
  private LocalDate loanDate;  // 借阅日期
  private LocalDate returnDate;  // 归还日期
  private static final int LOAN_PERIOD_DAYS = 30; // 假设借阅周期为30天
  private double finePerDay = 1.0; // 超期每天罚金

  public LoanRecord(Reader reader, Book book) {
    this.reader = reader;
    this.book = book;
    this.loanDate = LocalDate.now();
    this.returnDate = loanDate.plusDays(LOAN_PERIOD_DAYS); // 默认借阅期为30天
  }


  /**
   * 判断是否超期
   * @return
   */
  public boolean isOverdue() {
    return LocalDate.now().isAfter(returnDate);
  }

  /**
   * 计算罚款金额
   * @return
   */
  public double calculateFine() {
    if (isOverdue()) {
      long overdueDays = LocalDate.now().toEpochDay() - returnDate.toEpochDay();
      return overdueDays * finePerDay;
    }
    return 0;
  }

  /**
   * 设置归还日期 ， 默认为当前时间，测试时使用
   * @param minusDays
   */
  public void setReturnDate(LocalDate minusDays) {
    this.returnDate = minusDays;
  }

  // Getters and Setters
  public Reader getUser() {
    return reader;
  }

  public Book getBook() {
    return book;
  }

  public LocalDate getLoanDate() {
    return loanDate;
  }

  public LocalDate getReturnDate() {
    return returnDate;
  }
}
